<!--封装报警查询组件  未完待续-->
<template>
  <div>
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="船舶选择">
        <el-select v-model="formInline.ship" placeholder="船舶选择">
          <el-option
            v-for="item in shipList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="摄像机名称">
        <el-input
          placeholder="摄像机名称"
          v-model="formInline.cname"
          @keyup.enter.native="searchKeyup"
          clearable
        ></el-input>
      </el-form-item>

      <el-form-item label="起止时间">
        <el-date-picker
          v-model="formInline.time"
          type="datetimerange"
          :picker-options="pickerOptions"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          align="right"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button icon="el-icon-search" type="primary" @click="searchBtn"
          >查 询</el-button
        >
        <el-button icon="el-icon-refresh" type="warning" @click="refresh"
          >重 置</el-button
        >
        <el-button icon="el-icon-download" type="info" @click="exportPdf"
          >导 出</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  props: {
    //shipList: [Array, Object],
    shipList: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      formInline: {
        ship: "",
        cname: "",
        time: "",
      },
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },
  methods: {
    searchKeyup() {
      this.search();
    },
    searchBtn() {
      this.search();
    },
    search() {
      let filters = {};
      filters.ship = this.formInline.ship;
      filters.cname = this.formInline.cname;
      if (filters.cname == "" || filters.cname == null) {
        this.$message.warning("摄像机名称不能为空！");
        return;
      } else {
        this.$emit("searchEvent", filters);
      }
    },
    refresh() {
      //默认选择船
      //this.formInline.ship = this.shipList[0].value;
      this.formInline.ship = null;
      this.formInline.cname = null;
      this.formInline.time = null;
      this.$emit("refreshEvent");
    },
    exportPdf() {},
  },
  computed: {},
  created() {
    //默认选择船
    //this.formInline.ship = this.shipList[0].value;
  },
  mounted() {},
  watch: {},
};
</script>